package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.service.IDailishangService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dailishang;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 代理商 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/dailishang")
public class DailishangController extends BaseController
{
    private String prefix = "system/dailishang";
	
	@Autowired
	private IDailishangService dailishangService;
	
	@RequiresPermissions("system:dailishang:view")
	@GetMapping()
	public String dailishang()
	{
	    return prefix + "/dailishang";
	}
	
	/**
	 * 查询代理商列表
	 */
	@RequiresPermissions("system:dailishang:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Dailishang dailishang)
	{
		startPage();
        List<Dailishang> list = dailishangService.selectDailishangList(dailishang);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出代理商列表
	 */
	@RequiresPermissions("system:dailishang:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dailishang dailishang)
    {
    	List<Dailishang> list = dailishangService.selectDailishangList(dailishang);
        ExcelUtil<Dailishang> util = new ExcelUtil<Dailishang>(Dailishang.class);
        return util.exportExcel(list, "dailishang");
    }
	
	/**
	 * 新增代理商
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存代理商
	 */
	@RequiresPermissions("system:dailishang:add")
	@Log(title = "代理商", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Dailishang dailishang)
	{		
		return toAjax(dailishangService.insertDailishang(dailishang));
	}

	/**
	 * 修改代理商
	 */
	@GetMapping("/edit/{dailishangId}")
	public String edit(@PathVariable("dailishangId") Integer dailishangId, ModelMap mmap)
	{
		Dailishang dailishang = dailishangService.selectDailishangById(dailishangId);
		mmap.put("dailishang", dailishang);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存代理商
	 */
	@RequiresPermissions("system:dailishang:edit")
	@Log(title = "代理商", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Dailishang dailishang)
	{		
		return toAjax(dailishangService.updateDailishang(dailishang));
	}
	
	/**
	 * 删除代理商
	 */
	@RequiresPermissions("system:dailishang:remove")
	@Log(title = "代理商", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dailishangService.deleteDailishangByIds(ids));
	}
	
}
